__author__ = 'Jerry Liu'
import socket
import threading

outString = ''
inString = ''

HOST = input('Please input your server ip:')
nick = input('Please input your nick:')
PORT = 9000
ADDR = (HOST, PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(ADDR)
s.send(nick.encode())


def dealOut(conn):
    global outString
    while True:
        outString = input()
        outString = nick+':'+outString
        if not outString:
            return
        conn.send(outString.encode())

def dealIn(conn):
    global inString
    while True:
        inString = conn.recv(1024)
        if not inString:
            return
        if inString != outString:
            print(inString)


threading.Thread(target=dealIn, args=(s, )).start()
threading.Thread(target=dealOut, args=(s, )).start()